package com.longsunhd.yum.buffalo.base;

import android.graphics.Color;
import android.os.Build;
import android.support.v4.graphics.drawable.DrawableCompat;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.Toolbar;
import android.view.ViewGroup;
import android.widget.TextView;


import com.longsunhd.yum.buffalo.R;
import com.longsunhd.yum.buffalo.util.StatusBarUtil;
import com.longsunhd.yum.buffalo.util.UiUtil;

import butterknife.BindView;


//回退的activity
public class BackActivity extends BaseActivity {
    @BindView(R.id.toolbar)
    protected Toolbar mToolBar;

    @BindView(R.id.mTvTitle)
    protected TextView mTvTitle;

    @Override
    protected int getContentView() {
        return 0;
    }

    @Override
    protected void initWidget() {

        setTitle("");
        //设置状态栏字体颜色
        StatusBarUtil.setLightMode(this);
        if (mToolBar != null) {
            setSupportActionBar(mToolBar);
            ActionBar actionBar = getSupportActionBar();//使用ToolBar控件替代ActionBar控件，
            if (actionBar != null) {
                actionBar.setDisplayHomeAsUpEnabled(true);// 给左上角图标的左边加上一个返回的图标
                actionBar.setHomeButtonEnabled(false);//该方法的作用：决定左上角的图标是否可以点击。
            }

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                //状态栏高度
                int statusBarHeight = UiUtil.getStatusBarHeight(this);
                ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) mToolBar.getLayoutParams();
                params.topMargin = statusBarHeight;
                mToolBar.setLayoutParams(params);
            }

        }


    }

    //onSupportNavigateUp可以使用toolbar的后退按钮后退
    @Override
    public boolean onSupportNavigateUp() {
        finish();
        return super.onSupportNavigateUp();
    }


    @SuppressWarnings("ConstantConditions")
    protected void setDarkToolBar() {
        if (mToolBar != null) {
            mToolBar.setTitleTextColor(Color.BLACK);
            DrawableCompat.setTint(mToolBar.getNavigationIcon(), Color.BLACK);
        }
    }
}
